package com.youfang.sixthmedia;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.gzit.common.async.AsynCallback;
import com.gzit.utils.AndroidUtils;
import com.gzit.utils.StringUtils;
import com.youfang.sixthmedia.message.AddfeedbackMessageDelegate;
import com.youfang.sixthmedia.net.Net;
import com.youfang.sixthmedia.net.Response;

public class FeedbackActivity extends Activity {

	EditText content;
	EditText phone;
	EditText email;
	EditText name;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.feedback_activity);

		content = (EditText) this.findViewById(R.id.content);
		phone = (EditText) this.findViewById(R.id.phone);
		email = (EditText) this.findViewById(R.id.email);
		name = (EditText) this.findViewById(R.id.name);

		this.findViewById(R.id.feedbackbtn).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						remoteFeedBack();
					}
				});

	}

	public void remoteFeedBack() {
		if (StringUtils.isBlank(content.getText().toString())) {
			AndroidUtils.toastShort("内容不能为空");

			return;
		}

		if (StringUtils.isBlank(phone.getText().toString())) {
			AndroidUtils.toastShort("电话不能为空");
			return;
		}

		if (StringUtils.isBlank(email.getText().toString())) {
			AndroidUtils.toastShort("邮件不能为空");
			return;
		}

		if (StringUtils.isBlank(name.getText().toString())) {
			AndroidUtils.toastShort("姓名不能为空");

			return;
		}

		AddfeedbackMessageDelegate delegate = new AddfeedbackMessageDelegate();
		delegate.req.setContent(content.getText().toString());
		delegate.req.setEmail(email.getText().toString());
		delegate.req.setName(name.getText().toString());
		delegate.req.setPhone(phone.getText().toString());

		Net.message(this, delegate, new AsynCallback<Response>() {

			@Override
			public void callback(Response r) {
				if (r.isFail()) {
					AndroidUtils.toastShort("反馈失败");
					return;
				}

				AndroidUtils.toastShort("反馈成功，感谢您的反馈。");

			}
		});

	}

}
